/*
* PROJECT: Happy New Year
* VERSION: 1.0
* AUTHOR: Mattias Thell
* URL: http://www.mattiasthell.com
*
* */

#include <hge.h>
#include <hgeparticle.h>
#include <hgefont.h>
#include <hgeanim.h>

#include <math.h>

#include "World.hpp"
#include "Settings.hpp"
#include "AudioManager.hpp"

#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
#define COLOR_DEPTH 32

HGE *gHge = 0;
hny::World* gWorld = 0;

bool RenderFunc()
{
	return gWorld->Draw();
}

bool FrameFunc()
{
	float dt = gHge->Timer_GetDelta();

	return gWorld->Update(dt);
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	hny::Settings::GetInstance()->LoadSettings();

	gHge = hgeCreate(HGE_VERSION);

	gHge->System_SetState(HGE_LOGFILE, "HNY.log");
	gHge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	gHge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	gHge->System_SetState(HGE_WINDOWED, true);
	gHge->System_SetState(HGE_SCREENWIDTH, hny::Settings::GetInstance()->SystemScreenWidth);
	gHge->System_SetState(HGE_SCREENHEIGHT, hny::Settings::GetInstance()->SystemScreenHeight);
	gHge->System_SetState(HGE_SCREENBPP, hny::Settings::GetInstance()->SystemColorDepth);
	gHge->System_SetState(HGE_USESOUND, false);
	gHge->System_SetState(HGE_TITLE, "Happy New Year");
	gHge->System_SetState(HGE_HIDEMOUSE, false);
	
	if(!hny::Settings::GetInstance()->ShowSplash)
		gHge->System_SetState( HGE_SHOWSPLASH, false );

	if(gHge->System_Initiate())
	{
		hny::AudioManager::GetInstance()->Initialize();

		gWorld = new hny::World(gHge);
		gWorld->Initialize();

		gHge->System_Start();
	}
	else
	{	
	   MessageBox(NULL, (LPCWSTR)(gHge->System_GetErrorMessage()), L"Error", 
         MB_OK | MB_ICONERROR | MB_APPLMODAL);
	}

	delete gWorld;

	gHge->System_Shutdown();
	gHge->Release();

	return 0;
}